//
//  GYHTabBar.swift
//  SinaWeibo-18
//
//  Created by 高勇华 on 15/9/29.
//  Copyright © 2015年 高勇华. All rights reserved.
//

import UIKit

class GYHTabBar: UITabBar {

   
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        let w = UIScreen.mainScreen().bounds.width / 5
        
        let h = self.bounds.height
        
        let frame = CGRectMake(0, 0, w, h)
        
        var index:CGFloat = 0
        //print(self.subviews)
        
        for view in self.subviews{
        
            if view is UIControl && !(view is UIButton){
            
            view.frame = CGRectOffset(frame, w * index, 0)
                
                
                if index == 1 {
                
                index++
                    
//                  middleButton.frame = CGRectOffset(frame, 2 * w, h)
                
                }
                
            
                index++
                
             
            }
        
        
        }
       
        middleButton.frame = CGRectOffset(frame, 2 * w, 0)
    
    }
   
    
    
    lazy var middleButton : UIButton = {
        
        let but = UIButton(type: UIButtonType.Custom)
        
        but.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        
        but.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        
        but.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Selected)
        
        but.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Selected)
        

        
        self.addSubview(but)
        
        return but
    }()

    
    
    
    
    
    
    
}







